package com.future.mayi.activity;

import android.content.Context;
import android.content.Intent;
import android.widget.ListView;

import com.future.baselib.utils.ApiCst;
import com.future.baselib.utils.HttpRequest;
import com.future.mayi.R;
import com.future.mayi.adapter.CourierInfoAdapter;
import com.future.mayi.app.App;
import com.future.mayi.model.CourierInfoModel;
import com.future.mayi.response.GoodsOrderCourierResponse;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class CourierInfoActivity extends BaseTitleActivity {
    @BindView(R.id.list_view)
    ListView listView;

    private CourierInfoAdapter adapter;

    private String orderId;
    private String order_goods_id;
    private boolean appraisal;
    private int type = -1;

    private List<CourierInfoModel> list;


    //物流类型 0-寄出物流 1-回寄物流
    public static void startActivity(Context context, String orderId, boolean appraisal, int type) {
        Intent intent = new Intent(context, CourierInfoActivity.class);
        intent.putExtra("orderId", orderId);
        intent.putExtra("appraisal", appraisal);
        intent.putExtra("type", type);
        context.startActivity(intent);
    }

    public static void startActivity(Context context, String orderId, String order_goods_id, int type) {
        Intent intent = new Intent(context, CourierInfoActivity.class);
        intent.putExtra("orderId", orderId);
        intent.putExtra("order_goods_id", order_goods_id);
        intent.putExtra("type", type);
        context.startActivity(intent);
    }

    @Override
    protected void initTopBar() {
        initBack();
        getTitleText().setText("物流信息");
    }

    @Override
    protected void initLayout() {
        setContentView(R.layout.activity_courier_info);
    }

    @Override
    protected void initView() {
        list = new ArrayList<>();
        adapter = new CourierInfoAdapter(this, list);
        listView.setAdapter(adapter);
    }

    @Override
    protected void initDates() {
        orderId = getIntent().getStringExtra("orderId");
        appraisal = getIntent().getBooleanExtra("appraisal", false);
        order_goods_id = getIntent().getStringExtra("order_goods_id");
        type = getIntent().getIntExtra("type", type);
        getData();
    }

    private void getData() {
        String apiCode = ApiCst.getExpressInfo;
        if (appraisal) {
            apiCode = ApiCst.getExpressInfoOtherorder;
        } else if (order_goods_id != null) {
            apiCode = ApiCst.getExpressInfoConsignorder;
        }
        new HttpRequest<GoodsOrderCourierResponse>()
                .with(this).setApiCode(apiCode)
                .addParam("token", App.getToken(mContext))
                .addParam("order_id", orderId)
                .addParam("order_goods_id", order_goods_id)
                .addParam("type", type == -1 ? null : type)
                .setListener(new HttpRequest.OnNetworkListener<GoodsOrderCourierResponse>() {
                    @Override
                    public void onSuccess(GoodsOrderCourierResponse response) {
                        adapter.updateList(response.list);
                    }

                    @Override
                    public void onFail(String message, GoodsOrderCourierResponse response) {
                        toast(message);
                    }
                }).start(new GoodsOrderCourierResponse());
    }

    @Override
    protected void initListener() {

    }


}
